﻿using GPS.MODELS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GPS.DataAccessLayer;
using AutoMapper;
using PagedList;
using GPS.ENTITYS;
using GPS.COMMON;
using System.IO;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Oracle.ManagedDataAccess.Client;
using System.Data;
using Microsoft.AspNet.Identity;
using NPOI.HSSF.UserModel;
using OfficeOpenXml;
using System.Web.UI.WebControls;
using System.Web.UI;


namespace GPS.Controllers.GPS_Export
{
    public class GPS_DT_LuuLuongDTController : Controller
    {
        //
        // GET: /ExportHocVien_HopDong/
        #region Index
        DbContextHelper<GPS_NVContext> _db = Singleton<DbContextHelper<GPS_NVContext>>.Inst;
        public GPS.MODELS.ApplicationUser getCurrentUser()
        {
            ApplicationDbContext dbUser = new ApplicationDbContext();
            string userId = User.Identity.GetUserId();
            ApplicationUser _currentUser = dbUser.Users.Find(userId);
            return _currentUser;
        }
        public ActionResult Index(ViewModelDHV_Export SearchModel, int? currentPage)
        {
            SearchModel.pHV_DVGTVT_MA = this.getCurrentUser().MA_TINHTP;
            initialCategorySearchAction(SearchModel);
            var entities = _db.Filter<DHV>(o => (SearchModel.pHV_MA == null || o.HV_MA.StartsWith(SearchModel.pHV_MA))
                                                                  && (SearchModel.pHV_TEN == null || o.HV_HODEM.Contains(SearchModel.pHV_TEN) || o.HV_TEN.Contains(SearchModel.pHV_TEN))
                                                                  && (SearchModel.pHV_DVGTVT_MA == null || o.HV_DVGTVT_MA == SearchModel.pHV_DVGTVT_MA)
                                                                  && (SearchModel.pHV_KH_MA == null || o.HV_KH_MA == SearchModel.pHV_KH_MA)
                                                                  && (SearchModel.pHV_HANGDT_MA == null || o.HV_HANGDT_MA == SearchModel.pHV_HANGDT_MA)
                                                                  && (SearchModel.pHV_SOCMT == null || o.HV_SOCMT.StartsWith(SearchModel.pHV_SOCMT))
                                                                  );
            var model = new List<DHV>();
            foreach (var currentEntity in entities)
            {
                model.Add(Mapper.Map<DHV>(currentEntity));
            }
            Int16 icount = 1;
            foreach (var item in model)
            {
                item.STT = icount;
                icount++;
            }
            if (SearchModel.SearchButton == "Xuất danh sách")
            {
                try
                {
                    FileInfo template = new FileInfo(Server.MapPath(@"\Templates\GPS_Excel\DanhSachHocVien.xlsx"));
                    FileInfo newFile = new FileInfo(Server.MapPath(@"\Templates\GPS_Excel\CB_DonViHetHanGiayPhepNEW.xlsx"));

                    // Using the template to create the newFile...
                    using (OfficeOpenXml.ExcelPackage excelPackage = new OfficeOpenXml.ExcelPackage(newFile, template))
                    {
                        // Getting the complete workbook...
                        ExcelWorkbook myWorkbook = excelPackage.Workbook;
                        // Getting the worksheet by its name...
                        ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Sheet1"];
                        int recordIndex = 6;
                        foreach (var item in model)
                        {
                            myWorksheet.Cells[recordIndex, 1].Value = item.STT.ToString();
                            myWorksheet.Cells[recordIndex, 2].Value = item.HV_MA.ToString();
                            myWorksheet.Cells[recordIndex, 3].Value = item.HV_HODEM + " " + item.HV_TEN;
                            myWorksheet.Cells[recordIndex, 4].Value = item.HV_NGAYSINH == null ? "" : item.HV_NGAYSINH.ToString();
                            myWorksheet.Cells[recordIndex, 5].Value = item.HV_SOCMT == null ? "" : item.HV_SOCMT.ToString();
                            myWorksheet.Cells[recordIndex, 6].Value = item.HV_GIOITINH == null ? "" : item.HV_GIOITINH;
                            myWorksheet.Cells[recordIndex, 7].Value = item.HV_NOICT == null ? "" : item.HV_NOICT;
                            myWorksheet.Cells[recordIndex, 8].Value = item.HV_HANGDT_MA == null ? "" : item.HV_HANGDT_MA;
                            myWorksheet.Cells[recordIndex, 9].Value = item.HV_KH_MA == null ? "" : item.HV_KH_MA;
                            recordIndex++;
                        }
                        if (SearchModel.pHV_DVGTVT_MA != null)
                        {
                            myWorksheet.Cells[2, 1].Value = "Cơ sở giao thông vận tải" + _db.GetOne<SDONVIGTVT>(x => x.DVGTVT_MA == SearchModel.pHV_DVGTVT_MA).DVGTVT_TEN; ;
                        }
                        if (SearchModel.pHV_HANGDT_MA != null)
                        {
                            myWorksheet.Cells[3, 1].Value = "Hạng đào tạo: " + _db.GetOne<SHANGDT>(x => x.HANGDT_MA == SearchModel.pHV_HANGDT_MA).HANGDT_TEN; ;
                        }

                        if (SearchModel.pHV_KH_MA != null)
                        {
                            myWorksheet.Cells[4, 1].Value = "Khóa đào tạo: " + SearchModel.pHV_KH_MA;
                        }
                        excelPackage.Save();
                    }
                    string contentType = string.Empty;
                    string CurrentFileName = Server.MapPath(@"\Templates\GPS_Excel\CB_DonViHetHanGiayPhepNEW.xlsx");
                    if (CurrentFileName.Contains(".xlsx"))
                    {
                        contentType = "application/msexcel";
                    }
                    return File(CurrentFileName, contentType, "DanhSachHocVien_" + DateTime.Now.ToShortDateString() + ".xlsx");
                }
                catch (Exception ex)
                {
                    TempData["Message"] = ex.ToString();
                    return RedirectToAction("Index");
                }
            }
            else if ((SearchModel.SearchButton == "Xuất hợp đồng"))
            {
                foreach (var item in model)
                {
                    ExportDHV_hopDong _model = new ExportDHV_hopDong();
                    DataSet ds = OracleHelper.ExecuteDataset(_db.DbContext.Database.Connection.ConnectionString, CommandType.StoredProcedure, "GPS_DAOTAO.GPS_DAOTAO_HOPDONG"
                                                   , new OracleParameter("pDVGTVT_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(item.HV_DVGTVT_MA) ? DBNull.Value : (object)item.HV_DVGTVT_MA, ParameterDirection.Input)
                                                   , new OracleParameter("pHV_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(item.HV_MA) ? DBNull.Value : (object)item.HV_MA, ParameterDirection.Input)
                                                   , new OracleParameter("pRetBenA", OracleDbType.RefCursor, ParameterDirection.Output)
                                                    , new OracleParameter("pRetBenB", OracleDbType.RefCursor, ParameterDirection.Output)
                                                   , new OracleParameter("pRetCTDT", OracleDbType.RefCursor, ParameterDirection.Output)
                                                  );
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        _model.DVGTVT_TEN = ds.Tables[0].Rows[i]["DVGTVT_TEN"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEN"].ToString();
                        _model.DVGTVT_SOGP = ds.Tables[0].Rows[i]["DVGTVT_SOGP"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_SOGP"].ToString();
                        //_model.DVGTVT_NGAYGP = ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"] == null ? "" : Convert.ToDateTime( ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"]);
                        _model.DVGTVT_LANHDAO = ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"].ToString();
                        _model.DVGTVT_ADD = ds.Tables[0].Rows[i]["DVGTVT_ADD"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_ADD"].ToString();
                        _model.DVGTVT_TEL = ds.Tables[0].Rows[i]["DVGTVT_TEL"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEL"].ToString();
                        _model.DVGTVT_FAX = ds.Tables[0].Rows[i]["DVGTVT_FAX"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_FAX"].ToString();

                    }
                    for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                    {
                        _model.HOTEN = ds.Tables[1].Rows[i]["HOTEN"] == null ? "" : ds.Tables[1].Rows[i]["HOTEN"].ToString();
                        _model.HV_NGAYSINH = ds.Tables[1].Rows[i]["HV_NGAYSINH"] == null ? "" : ds.Tables[1].Rows[i]["HV_NGAYSINH"].ToString();
                        _model.HV_NOICT = ds.Tables[1].Rows[i]["HV_NOICT"] == null ? "" : ds.Tables[1].Rows[i]["HV_NOICT"].ToString();
                        _model.HV_DANGKY = ds.Tables[1].Rows[i]["HV_DANGKY"] == null ? "" : ds.Tables[1].Rows[i]["HV_DANGKY"].ToString();
                    }

                    _model.LISTHopDong = COMMON.Helpers.MapDataTableToList<ExportDHV_hopDong>(ds.Tables[2]);

                    _model.DATETIME_NOW = DateTime.Now.ToShortDateString();
                    _model.SOHOPDONG = item.ID.ToString();
                    _model.KH_TEN = item.HV_KH_MA;
                    byte[] contentFile = null;
                    contentFile = GPS.ENTITYS.EXPORTWORD_DHV_HopDong.EXPORT_HOCVIENHD(Server.MapPath("~/Templates/GPS_Word/HopDongDaoTaoLaiXe1.docx"), _model, "DocxGenericReport");
                    string nameOutput = "HopDongDaoTaoLaiXe_" + _model.HOTEN + DateTime.Now.ToShortDateString() + ".docx";
                    return File(contentFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", nameOutput);
                }
                return RedirectToAction("Index");
            }
            else if ((SearchModel.SearchButton == "Xuất thanh lý"))
            {
                foreach (var item in model)
                {
                    ExportDHV_TLhopDong _model = new ExportDHV_TLhopDong();
                    DataSet ds = OracleHelper.ExecuteDataset(_db.DbContext.Database.Connection.ConnectionString, CommandType.StoredProcedure, "GPS_DAOTAO.GPS_DAOTAO_TLHOPDONG"
                                                            , new OracleParameter("pDVGTVT_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(item.HV_DVGTVT_MA) ? DBNull.Value : (object)item.HV_DVGTVT_MA, ParameterDirection.Input)
                                                            , new OracleParameter("pHV_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(item.HV_MA) ? DBNull.Value : (object)item.HV_MA, ParameterDirection.Input)
                                                            , new OracleParameter("pRetBenA", OracleDbType.RefCursor, ParameterDirection.Output)
                                                             , new OracleParameter("pRetBenB", OracleDbType.RefCursor, ParameterDirection.Output)
                        //, new OracleParameter("pRetCTDT", OracleDbType.RefCursor, ParameterDirection.Output)
                                                           );
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        _model.DVGTVT_TEN = ds.Tables[0].Rows[i]["DVGTVT_TEN"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEN"].ToString();
                        _model.DVGTVT_SOGP = ds.Tables[0].Rows[i]["DVGTVT_SOGP"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_SOGP"].ToString();
                        // _model.DVGTVT_NGAYGP = ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"] == null ? "" : Convert.ToDateTime( ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"].ToString());
                        _model.DVGTVT_LANHDAO = ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"].ToString();
                        _model.DVGTVT_ADD = ds.Tables[0].Rows[i]["DVGTVT_ADD"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_ADD"].ToString();
                        _model.DVGTVT_TEL = ds.Tables[0].Rows[i]["DVGTVT_TEL"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEL"].ToString();
                        _model.DVGTVT_FAX = ds.Tables[0].Rows[i]["DVGTVT_FAX"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_FAX"].ToString();

                    }

                    for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                    {
                        _model.HOTEN = ds.Tables[1].Rows[i]["HOTEN"] == null ? "" : ds.Tables[1].Rows[i]["HOTEN"].ToString();
                        _model.HV_NGAYSINH = ds.Tables[1].Rows[i]["HV_NGAYSINH"] == null ? "" : ds.Tables[1].Rows[i]["HV_NGAYSINH"].ToString();
                        _model.HV_NOICT = ds.Tables[1].Rows[i]["HV_NOICT"] == null ? "" : ds.Tables[1].Rows[i]["HV_NOICT"].ToString();
                        _model.HV_DANGKY = ds.Tables[1].Rows[i]["HV_DANGKY"] == null ? "" : ds.Tables[1].Rows[i]["HV_DANGKY"].ToString();
                    }
                    _model.DATETIME_NOW = DateTime.Now.ToShortDateString();
                    _model.SOHOPDONG = item.ID.ToString();
                    _model.KH_TEN = _db.GetOne<DKH>(x => x.KH_MA == item.HV_KH_MA).KH_TEN;


                    byte[] contentFile = null;
                    contentFile = GPS.ENTITYS.EXPORTWORD_DHV_TLHopDong.EXPORT_HOCVIENTLHD(Server.MapPath("~/Templates/GPS_Word/ThanhLyHopDongDaoTaoLaiXe.docx"), _model, "DocxGenericReport");
                    string nameOutput = "ThanhLyHopDongDaoTaoLaiXe_" + _model.HOTEN + "_" + DateTime.Now.ToShortDateString() + ".docx";
                    return File(contentFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", nameOutput);
                }
                return View(SearchModel);
            }
            else
            {
                var pageIndex = SearchModel.Page ?? 1;
                SearchModel.SearchResults = model.ToPagedList(pageIndex, GPS.COMMON.Constants.PageSize);
                return View(SearchModel);
            }

        }
        public void initialCategorySearchAction(ViewModelDHV_Export viewModel)
        {
            ViewBag.HV_DVGTVT_MAs = new SelectList(_db.Filter<SDONVIGTVT>(o => o.DVGTVT_MAQL == "40"), "DVGTVT_MA", "DVGTVT_TEN");
            ViewBag.HV_HANGDT_MAs = new SelectList(_db.GetAll<SHANGDT>(), "HANGDT_MA", "HANGDT_TEN");
            ViewBag.HV_KH_MA = new SelectList(_db.Filter<DKH>(x => x.KH_DVGTVT_MA == viewModel.pHV_DVGTVT_MA), "KH_MA", "KH_TEN");
            ViewBag.TotalRow = _db.GetAll<DHV>().Count();
        }
        #endregion

        public ActionResult ExportWordHopDong(DHV model)
        {
            ExportDHV_hopDong _model = new ExportDHV_hopDong();
            DataSet ds = OracleHelper.ExecuteDataset(_db.DbContext.Database.Connection.ConnectionString, CommandType.StoredProcedure, "GPS_DAOTAO.GPS_DAOTAO_HOPDONG"
                                                    , new OracleParameter("pDVGTVT_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(model.HV_DVGTVT_MA) ? DBNull.Value : (object)model.HV_DVGTVT_MA, ParameterDirection.Input)
                                                    , new OracleParameter("pHV_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(model.HV_MA) ? DBNull.Value : (object)model.HV_MA, ParameterDirection.Input)
                                                    , new OracleParameter("pRetBenA", OracleDbType.RefCursor, ParameterDirection.Output)
                                                     , new OracleParameter("pRetBenB", OracleDbType.RefCursor, ParameterDirection.Output)
                                                    , new OracleParameter("pRetCTDT", OracleDbType.RefCursor, ParameterDirection.Output)
                                                   );
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                _model.DVGTVT_TEN = ds.Tables[0].Rows[i]["DVGTVT_TEN"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEN"].ToString();
                _model.DVGTVT_SOGP = ds.Tables[0].Rows[i]["DVGTVT_SOGP"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_SOGP"].ToString();
                //_model.DVGTVT_NGAYGP = ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"] == null ? "" : Convert.ToDateTime( ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"]);
                _model.DVGTVT_LANHDAO = ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"].ToString();
                _model.DVGTVT_ADD = ds.Tables[0].Rows[i]["DVGTVT_ADD"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_ADD"].ToString();
                _model.DVGTVT_TEL = ds.Tables[0].Rows[i]["DVGTVT_TEL"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEL"].ToString();
                _model.DVGTVT_FAX = ds.Tables[0].Rows[i]["DVGTVT_FAX"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_FAX"].ToString();

            }
            for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
            {
                _model.HOTEN = ds.Tables[1].Rows[i]["HOTEN"] == null ? "" : ds.Tables[1].Rows[i]["HOTEN"].ToString();
                _model.HV_NGAYSINH = ds.Tables[1].Rows[i]["HV_NGAYSINH"] == null ? "" : ds.Tables[1].Rows[i]["HV_NGAYSINH"].ToString();
                _model.HV_NOICT = ds.Tables[1].Rows[i]["HV_NOICT"] == null ? "" : ds.Tables[1].Rows[i]["HV_NOICT"].ToString();
                _model.HV_DANGKY = ds.Tables[1].Rows[i]["HV_DANGKY"] == null ? "" : ds.Tables[1].Rows[i]["HV_DANGKY"].ToString();
            }

            _model.LISTHopDong = COMMON.Helpers.MapDataTableToList<ExportDHV_hopDong>(ds.Tables[2]);

            _model.DATETIME_NOW = DateTime.Now.ToShortDateString();
            _model.SOHOPDONG = model.ID.ToString();
            _model.KH_TEN = _db.GetOne<DKH>(x => x.KH_MA == model.HV_KH_MA).KH_TEN;


            byte[] contentFile = null;
            contentFile = GPS.ENTITYS.EXPORTWORD_DHV_HopDong.EXPORT_HOCVIENHD(Server.MapPath("~/Templates/GPS_Word/HopDongDaoTaoLaiXe1.docx"), _model, "DocxGenericReport");
            string nameOutput = "HopDongDaoTaoLaiXe_" + _model.HOTEN + DateTime.Now.ToShortDateString() + ".docx";
            return File(contentFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", nameOutput);
        }
        public ActionResult ExportWordThanhLyHopDong(DHV model)
        {
            ExportDHV_TLhopDong _model = new ExportDHV_TLhopDong();
            DataSet ds = OracleHelper.ExecuteDataset(_db.DbContext.Database.Connection.ConnectionString, CommandType.StoredProcedure, "GPS_DAOTAO.GPS_DAOTAO_TLHOPDONG"
                                                    , new OracleParameter("pDVGTVT_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(model.HV_DVGTVT_MA) ? DBNull.Value : (object)model.HV_DVGTVT_MA, ParameterDirection.Input)
                                                    , new OracleParameter("pHV_MA", OracleDbType.Varchar2, string.IsNullOrWhiteSpace(model.HV_MA) ? DBNull.Value : (object)model.HV_MA, ParameterDirection.Input)
                                                    , new OracleParameter("pRetBenA", OracleDbType.RefCursor, ParameterDirection.Output)
                                                     , new OracleParameter("pRetBenB", OracleDbType.RefCursor, ParameterDirection.Output)
                //, new OracleParameter("pRetCTDT", OracleDbType.RefCursor, ParameterDirection.Output)
                                                   );
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                _model.DVGTVT_TEN = ds.Tables[0].Rows[i]["DVGTVT_TEN"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEN"].ToString();
                _model.DVGTVT_SOGP = ds.Tables[0].Rows[i]["DVGTVT_SOGP"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_SOGP"].ToString();
                // _model.DVGTVT_NGAYGP = ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"] == null ? "" : Convert.ToDateTime( ds.Tables[0].Rows[i]["DVGTVT_NGAYGP"].ToString());
                _model.DVGTVT_LANHDAO = ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_LANHDAO"].ToString();
                _model.DVGTVT_ADD = ds.Tables[0].Rows[i]["DVGTVT_ADD"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_ADD"].ToString();
                _model.DVGTVT_TEL = ds.Tables[0].Rows[i]["DVGTVT_TEL"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_TEL"].ToString();
                _model.DVGTVT_FAX = ds.Tables[0].Rows[i]["DVGTVT_FAX"] == null ? "" : ds.Tables[0].Rows[i]["DVGTVT_FAX"].ToString();

            }

            for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
            {
                _model.HOTEN = ds.Tables[1].Rows[i]["HOTEN"] == null ? "" : ds.Tables[1].Rows[i]["HOTEN"].ToString();
                _model.HV_NGAYSINH = ds.Tables[1].Rows[i]["HV_NGAYSINH"] == null ? "" : ds.Tables[1].Rows[i]["HV_NGAYSINH"].ToString();
                _model.HV_NOICT = ds.Tables[1].Rows[i]["HV_NOICT"] == null ? "" : ds.Tables[1].Rows[i]["HV_NOICT"].ToString();
                _model.HV_DANGKY = ds.Tables[1].Rows[i]["HV_DANGKY"] == null ? "" : ds.Tables[1].Rows[i]["HV_DANGKY"].ToString();
            }
            _model.DATETIME_NOW = DateTime.Now.ToShortDateString();
            _model.SOHOPDONG = model.ID.ToString();
            _model.KH_TEN = _db.GetOne<DKH>(x => x.KH_MA == model.HV_KH_MA).KH_TEN;


            byte[] contentFile = null;
            contentFile = GPS.ENTITYS.EXPORTWORD_DHV_TLHopDong.EXPORT_HOCVIENTLHD(Server.MapPath("~/Templates/GPS_Word/ThanhLyHopDongDaoTaoLaiXe.docx"), _model, "DocxGenericReport");
            string nameOutput = "ThanhLyHopDongDaoTaoLaiXe_" + _model.HOTEN + "_" + DateTime.Now.ToShortDateString() + ".docx";
            return File(contentFile, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", nameOutput);
        }
    }
}